home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / devConsoleCmd.c < prev    next >
C/C++ Source or Header  |  1991-08-11  |  6KB  |  216 lines

  1. /* 
  2.  * devConsoleCmd.c --
  3.  *
  4.  *    This file provides the mechanism for invoking certain kernel
  5.  *    operations by typing certain key sequences on the console (e.g.
  6.  *    on Sun-3's, L1-D puts the machine into the debugger).
  7.  *
  8.  * Copyright 1989 Regents of the University of California
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifndef lint
  19. static char rcsid[] = "$Header: /sprite/src/kernel/dev/RCS/devConsoleCmd.c,v 9.6 90/12/06 22:08:32 shirriff Exp $ SPRITE (Berkeley)";
  20. #endif /* not lint */
  21.  
  22. #include <sprite.h>
  23. #include <stdio.h>
  24. #include <dbg.h>
  25. #include <machMon.h>
  26. #include <net.h>
  27. #include <devVid.h>
  28.  
  29. /*
  30.  * Information about registered commands:
  31.  */
  32.  
  33. static struct {
  34.     void (*proc) _ARGS_ ((ClientData clientData));   /* Procedure to invoke. */
  35.     ClientData clientData;                      /* Argument to pass to proc. */
  36. } commands[256];
  37.  
  38. /*
  39.  * Forward declarations for procedures defined later in this file:
  40.  */
  41.  
  42. static void Abort _ARGS_((ClientData clientData));
  43. static void Debug _ARGS_((ClientData clientData));
  44.  
  45.  
  46. /*
  47.  *----------------------------------------------------------------------
  48.  *
  49.  * Dev_RegisterConsoleCmd --
  50.  *
  51.  *    This procedure is called to declare the procedure to be invoked
  52.  *    when a particular console command is invoked.  Console commands
  53.  *    are defined by a single ASCII character, e.g. "d" for debug.
  54.  *    The specific invocation sequence depends on the machine and
  55.  *    configuration.  On Sun-3's with console displays, L1-x is
  56.  *    typed to invoke the command associated with "x";  on servers
  57.  *    with no display, BREAK-x is typed to do the same thing.
  58.  *
  59.  * Results:
  60.  *    None.
  61.  *
  62.  * Side effects:
  63.  *    Whenever the given command is invoked, proc will be called.
  64.  *    It should have the following structure:
  65.  *
  66.  *    void
  67.  *    proc(clientData)
  68.  *    {
  69.  *    }
  70.  *
  71.  *    The clientData argument will be the same as the clientData
  72.  *    argument passed to this procedure.  Note:  proc will always
  73.  *    be invoked at background level in a kernel server process.
  74.  *
  75.  *----------------------------------------------------------------------
  76.  */
  77.  
  78. void
  79. Dev_RegisterConsoleCmd(commandChar, proc, clientData)
  80.     int commandChar;        /* ASCII character associated with command. */
  81.     void (*proc) _ARGS_ ((ClientData clientData));
  82.                                 /* Procedure to call when command is
  83.                  * invoked. */
  84.     ClientData clientData;    /* Arbitrary one-word value to pass to
  85.                  * command. */
  86. {
  87.     int index = commandChar & 0x7f;
  88.  
  89.     if (commands[index].proc != 0) {
  90.     printf("%s for \"%c\" (0x%x).\n",
  91.         "Warning: Dev_RegisterConsoleCmd replacing procedure",
  92.         commandChar, index);
  93.     }
  94.     commands[index].proc = proc;
  95.     commands[index].clientData = clientData;
  96. }
  97.  
  98. /*
  99.  *----------------------------------------------------------------------
  100.  *
  101.  * Dev_InvokeConsoleCmd --
  102.  *
  103.  *    Given a command character, this procedure invokes the console
  104.  *    command associated with the character.
  105.  *
  106.  * Results:
  107.  *    None.
  108.  *
  109.  * Side effects:
  110.  *    If there is a procedure registered for commandChar, it is
  111.  *    invoked.
  112.  *
  113.  *----------------------------------------------------------------------
  114.  */
  115.  
  116. void
  117. Dev_InvokeConsoleCmd(commandChar)
  118.     int commandChar;
  119. {
  120.     /*
  121.      * The initialization code below should be removed;  the debugger
  122.      * module should register its own commands.
  123.      */
  124.  
  125.     if (commands['a'].proc == 0) {
  126.     commands['a'].proc = Abort;
  127.     }
  128.     if (commands['b'].proc == 0) {
  129.     commands['b'].proc = Debug;
  130.     commands['b'].clientData = (ClientData) TRUE;
  131.     }
  132.     if (commands['d'].proc == 0) {
  133.     commands['d'].proc = Debug;
  134.     commands['d'].clientData = (ClientData) FALSE;
  135.     }
  136.  
  137.     /*
  138.      * Turn on the video.
  139.      */
  140.     (void) Dev_VidEnable(TRUE);
  141.  
  142.     commandChar &= 0x7f;
  143.     if (commands[commandChar].proc != 0) {
  144.     (*commands[commandChar].proc)(commands[commandChar].clientData);
  145.     }
  146. }
  147.  
  148. /*
  149.  *----------------------------------------------------------------------
  150.  *
  151.  * Abort, Debug --
  152.  *
  153.  *    These are temporary procedures to handle some of the console
  154.  *    commands;  they should be moved out of this module.
  155.  *
  156.  * Results:
  157.  *    None.
  158.  *
  159.  * Side effects:
  160.  *    Depends on command.
  161.  *
  162.  *----------------------------------------------------------------------
  163.  */
  164.  
  165. static void
  166. Abort(clientData)
  167.     ClientData clientData;
  168. {
  169.     int            i;
  170.     Net_Interface    *interPtr;
  171.     Mach_MonAbort();
  172.     i = 0;
  173.     interPtr = Net_NextInterface(FALSE, &i);
  174.     while(interPtr != (Net_Interface *) NIL) {
  175.     Net_Reset(interPtr);
  176.     i++;
  177.     interPtr = Net_NextInterface(FALSE, &i);
  178.     }
  179. }
  180.  
  181. static void
  182. Debug(clientData)
  183.     ClientData clientData;
  184. {
  185.  
  186.     DBG_CALL;
  187. }
  188.  
  189. /*
  190.  *----------------------------------------------------------------------
  191.  *
  192.  * Dev_KbdQueueAttachProc --
  193.  *
  194.  *    This procedure is a temporary hack during the conversion to
  195.  *    the new tty driver.  All calls to it should be redirected
  196.  *    to Dev_RegisterConsoleCmd.
  197.  *
  198.  * Results:
  199.  *    None.
  200.  *
  201.  * Side effects:
  202.  *    See Dev_RegisterConsoleCmd.
  203.  *
  204.  *----------------------------------------------------------------------
  205.  */
  206.  
  207. int
  208. Dev_KbdQueueAttachProc(character, proc, clientData)
  209.     int character;
  210.     void (*proc) _ARGS_ ((ClientData clientData));
  211.     ClientData clientData;
  212. {
  213.     Dev_RegisterConsoleCmd(character, proc, clientData);
  214.     return 0;
  215. }
  216.